<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="修改密码">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">

    <script>
        jQuery(function () {
            $("#cancel").click(function () {
                closeSubIframe();
            });
        });
        layui.use(['form', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table;

            //自定义验证规则
            form.verify({
                oldPassword: [
                    /^[\S]{6,12}$/
                    ,'原密码必须6到12位，且不能出现空格'
                ]
                ,password: [
                    /^[\S]{6,12}$/
                    ,'新密码必须6到12位，且不能出现空格'
                ]
                ,entryPassword: function(value){
                    if(value.match(/^[\S]{6,12}$/) == null){
                        return '确认密码必须6到12位，且不能出现空格';
                    }
                    var password = $("[name='password']").val();
                    if (password != value) {
                        return '确认密码与新密码不一致';
                    }

                    var oldPassword = $("[name='oldPassword']").val();
                    if (oldPassword == value) {
                        return '原密码与新密码不能一样';
                    }
                }
            });

            form.on('submit(save)', function (data) {
                console.log(JSON.stringify(data.field));
                delete data.field.entryPassword;
                tipLoad("密码修改中");
                post("${baseUrl}user/user/changePassword.action", data.field,function (resp) {
                    closeAll();
                    if (resp.code == 1) {
                        tip("密码修改成功");
                        closeSubIframe();
                    } else {
                        closeLoading();
                        tip(resp.msg);
                    }
                });

                return false;
            });
        });
    </script>

</html:header>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form" action="" lay-filter="changePassword">
            <input type="hidden" name="id" value="${id}">

            <div class="layui-form-item">
                <label class="layui-form-label">原密码</label>
                <div class="layui-input-block">
                    <input type="password" name="oldPassword" placeholder="原密码"  lay-verify="oldPassword" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" placeholder="新密码"  lay-verify="password" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-block">
                    <input type="password" name="entryPassword" placeholder="确认密码"  lay-verify="entryPassword" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="save">保存</button>
                    <button class="layui-btn layui-btn-primary" id="cancel">取消</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<html:loading/>
</html>